require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported

target 'example' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false,
    # :flipper_configuration => FlipperConfiguration.enabled,
  )

  post_install do |installer|
    __apply_update_deployment_target_workaround(installer)
    __apply_Xcode_15_workaround(installer)

     react_native_post_install(
       installer,
       config[:reactNativePath],
       # Set `mac_catalyst_enabled` to `true` in order to apply patches
       # necessary for Mac Catalyst builds
       :mac_catalyst_enabled => false
     )
  end
end

def __apply_update_deployment_target_workaround(installer)
  # This is a workaround for updating the deployment target of pod targets to the minimal supported version.
  # See StackOverflow: https://stackoverflow.com/questions/72729591/fbreactnativespec-h-error-after-upgrading-from-0-68-x-to-0-69-0/75915794#75915794
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '5.0'
      if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] < '12.4'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4'
      end
    end
  end
end

def __apply_Xcode_15_workaround(installer)
  # This is a workaround for Xcode 15, see: https://github.com/facebook/react-native/issues/37748.
  puts "Applying Xcode 15 post install workaround"
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
    end
  end
end
